package com.woniuxy.propertyjava.controller;

import com.woniuxy.propertyjava.entity.Cleaning;
import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.ResponseResult;
import com.woniuxy.propertyjava.service.CleaningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : author
 * @create 2022/7/5 17:41
 */
@RestController
public class CleaningController {

    @Autowired
    CleaningService cleaningService;

    @PostMapping("/cleaning/{pageIndex}/{pageSize}")
    public ResponseResult<PageBean<Cleaning>> getCleaningsByPage(@PathVariable("pageIndex") int pageIndex,
                                                                 @PathVariable("pageSize") int pageSize,
                                                                 @RequestBody Cleaning cleaning) {
        PageBean<Cleaning> pageBean = cleaningService.getCleaningPageBean(cleaning, pageIndex, pageSize);
        ResponseResult<PageBean<Cleaning>> responseResult = new ResponseResult<PageBean<Cleaning>>(200, "ok", pageBean);
        return responseResult;
    }

    @PostMapping("/cleaning")
    public ResponseResult addCleaning(@RequestBody Cleaning cleaning) {
        cleaningService.insertCleaning(cleaning);
        ResponseResult responseResult = new ResponseResult<>(200, "添加成功", null);
        return responseResult;
    }

    @PutMapping("/cleaning")
    public ResponseResult changeCleaning(@RequestBody Cleaning cleaning) {
        cleaningService.updataCleaning(cleaning);
        ResponseResult responseResult = new ResponseResult<>(200, "修改成功", null);
        return responseResult;
    }

    @DeleteMapping("/cleaning/{cleaningId}")
    public ResponseResult reduceCleaning(@PathVariable("cleaningId") int cleaningId) {
        cleaningService.deleteCleaning(cleaningId);
        ResponseResult responseResult = new ResponseResult<>(200, "删除成功", null);
        return responseResult;
    }
}
